from typing import Union, List, Iterable

from scripts.device.AdbDevice import AdbDevice


class DeviceMonitor(object):
    def __init__(self):
        pass

    @staticmethod
    def wait_for_device(include: Union[None, Iterable[str]] = None,
                        exclude: Union[None, Iterable[str]] = None) -> List[AdbDevice]:
        include = set() if include is None else set(include)
        exclude = set() if exclude is None else set(exclude)

        # wait for device
        while True:
            AdbDevice.wait_for_device()
            devices = AdbDevice.devices()

            d = set(devices) & include - exclude
            if len(d) > 0:
                return [AdbDevice(sn) for sn in d]
